#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main ()
{
    printf("父(main)进程(%d)开始执行 \n", getpid());
    
    pid_t pid = fork();
    if (pid > 0) // 父进程
    {
        printf("父进程(%d)执行\n", getpid());
    }
    else if (pid == 0) // 子进程
    {
        printf("子进程(%d)执行\n", getpid());

        char *argv[] = {"/home/zxf/桌面/linux_study/linux_test/3_Process/other", NULL};
        char *envp[] = {NULL};

        int result = execve(argv[0], argv, envp);
        if (result == -1)
        {
            perror("execve执行程序失败");
            return 1;
        }
    }
    else // 失败
    {
        perror("创建子进程失败");
        return 1;
    }

    return 0;
}